import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

export const constantRoutes = [
  {
    path: '/',
    redirect: '/app/index',
  },
  {
    path: '/app/user/login',
    name: '登录',
    component: () => import('@/views/app/user/login'),
    hidden: true,
    meta: { title: '登录' }
  },
  {
    path: '/app/user/self',
    name: '我的',
    component: () => import('@/views/app/user/self'),
    hidden: true,
    meta: { title: '我的' }
  },
  {
    path: '/app/user/test',
    name: 'test',
    component: () => import('@/views/app/components/footer'),
    hidden: true,
    meta: { title: 'test' }
  },
  {
    path: '/app/user/register',
    name: '注册',
    component: () => import('@/views/app/user/register'),
    hidden: true,
    meta: { title: '注册' }
  },
  {
    path: '/app/user/forget',
    name: '忘记密码',
    component: () => import('@/views/app/user/forget'),
    hidden: true,
    meta: { title: '忘记密码' }
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  {
    path: '/app/index',
    component: () => import('@/views/app/index'),
    hidden: true
  },
  {
    path: '/app/search/index',
    name: 'SearchIndexRouter',
    component: () => import('@/views/app/search/index'),
    hidden: true
  },
  {
    path: '/app/shop/index',
    name: 'Shop',
    component: () => import('@/views/app/shop/index'),
    hidden: true
  },
  {
    path: '/app/goods/index',
    name: 'Goods',
    component: () => import('@/views/app/goods/index'),
    hidden: true
  },
]
export const asyncRoutes = [

]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
